<?php

use App\Enums\CustomerLabel;
use App\Enums\CustomerStatus;
use App\Enums\Gender;
use App\Enums\ReceptionType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('source_option_id')->default(0)->comment('数据来源');
            $table->unsignedBigInteger('reception_user_id')->default(0)->comment('接待部人');
            $table->unsignedBigInteger('sale_user_id')->default(0)->comment('销售部人');
            $table->timestamp('sale_time')->nullable()->comment(' 销售部接待时间');
            $table->string('name', 255)->default('')->comment('姓名');
            $table->string('phone', 255)->index()->default('')->comment('手机');
            $table->string('id_card', 255)->default('')->comment('身份证号');
            $table->string('wechat', 255)->default('')->comment('微信');
            $table->unsignedTinyInteger('age')->default(0)->comment('年龄');
            $table->unsignedTinyInteger('gender')->default(Gender::UNKNOWN)->comment('性别:0=未知,1=男,2=女');
            $table->unsignedInteger('province_id')->default(0)->comment('省');
            $table->unsignedInteger('city_id')->default(0)->comment('市');
            $table->unsignedInteger('district_id')->default(0)->comment('区');
            $table->string('address', 255)->default('')->comment('详细地址');
            $table->unsignedTinyInteger('customer_label')->default(CustomerLabel::NOT)->comment('客户标签');

            $table->unsignedBigInteger('doctor_option_id')->default(0)->comment('预约专家');
            $table->string('disease')->default('')->comment('病种');
            $table->text('symptom')->nullable()->comment('症状');
            $table->timestamp('time_of_appointment')->nullable()->comment('预约时间(即挂号了)');
            $table->text('treatment_history')->nullable()->comment('治疗历史');
            $table->timestamp('deal')->nullable()->comment('成交时间(null代表未成交)');
            $table->text('sale_remark')->nullable()->comment('销售备注');
            $table->timestamp('consultation')->nullable()->comment('看诊时间(null代表未就诊)');

            $table->unsignedBigInteger('return_user_id')->default(0)->comment(' 复诊部人');
            $table->timestamp('return_time')->nullable()->comment(' 复诊部接待时间');
            $table->text('return_remark')->nullable()->comment('复诊备注');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customers');
    }
}
